package t3;

import java.util.Calendar;
import java.util.List;

import t3bean.CarBean;
import t3bean.ChargeRecordBean;
import t3bean.ParkingLotBean;
import t3bean.ParkingSpaceBean;

/**
 * 取车操作
 *
 */
public class ChargeCar {
	public ParkingLotBean chargeCar(ParkingLotBean pl, String licensePlate, Integer id) {
		List<ParkingSpaceBean> pSList = pl.getpSList();
		for (ParkingSpaceBean ps : pSList) {
			// 判断停车位和车牌号是否正确
			if (ps.getId() == id && ps.getCar().getLicensePlate().equals(licensePlate)) {
				ps.setIsParking(0);
				ps.setCar(new CarBean(" ",0));
				ps.setParkingTime((long) 0);
				// 获取现在时间
				Calendar cal = Calendar.getInstance();
				long datelong = cal.getTimeInMillis();
				datelong = ps.getParkingTime() - datelong;
				// 计算时间和钱
				long hours = (datelong % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
				Integer charge = (int) hours * 2;
				ChargeRecordBean cr = new ChargeRecordBean(licensePlate, charge);
				pl.getcRList().add(cr);
				System.out.println("缴费成功");
				break;
			} else {
				System.out.println("失败");
			}
		}
		return pl;
	}
}
